
{include file="public/top" /}
<style>

</style>
<body class="layui-anim layui-anim-up">

<div class="x-body">
    <div class="layui-row clear pagesa">
        <p class="fl">>系统日志</p>
        <button class="layui-btn layui-btn-danger fr" id="del" type="button"><i class="layui-icon"></i>批量删除</button>
    </div>
    <table class="" lay-filter="test" id="table">
    </table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
</div>
<script>
    var listurl = '/admin/adminlog/getList';
    var delurl = '/admin/adminlog/del';
    var delAllUrl = '/admin/adminlog/delAll';
    layui.use('table', function(){
        var table = layui.table;
        table.render({
            elem: '#table'
            ,height: 'full-95'
            ,url: listurl //数据接口
            ,page: true //开启分页
            ,limit:20
            ,limits:[20,100,300]
            ,id:'idTest'
            ,cols: [[ //表头
                {field: 'id',width:40,title: 'ID', fixed: 'left'}
                ,{type: 'checkbox'}
                ,{field: 'name', title: '用户名'}
                ,{field: 'motion', title: '操作内容' }
                ,{field: 'create_time', title: '操作时间',  sort: true}
                ,{field: 'ip', title: '操作IP'}
                ,{fixed: 'right', align:'center', toolbar: '#barDemo'}
            ]]
        });
        //监听表格复选框选择
        //监听工具条
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: delurl,
                        data: {'id':data.id},
                        success: function (res) {
                            var success = JSON.parse(res);
                            if(success.code==200){
                                layer.msg(success.msg);
                                obj.del();
                                layer.close(index);
                            }else {
                                layer.msg(success.msg)
                            }

                        }
                    });

                });
            }

        });
        $('#del').click(function () {
            var checkStatus = table.checkStatus('idTest');
            if(checkStatus.data.length==0){
                layer.msg("请选择要删除的行")
                return false;
            }
            layer.confirm('真的删除行么', function(index){
                var data1 = checkStatus.data;
                var data2 = [];
                for (var i=0;i<data1.length;i++)
                {
                    data2[i] = data1[i].id;
                }
                $.ajax({
                    type: "POST",
                    dataType: "json",
                    url: delAllUrl,
                    data: {data:data2},
                    success: function (res) {
                        var success = JSON.parse(res);
                        if(success.code==200){
                            layer.msg(success.msg);
                            table.reload('idTest', {
                                url: listurl
                                ,where: {'name':0} //设定异步数据接口的额外参数
                                //,height: 300
                            });
                        }else {
                            layer.msg(success.msg)
                        }

                    }
                });
            });
        })


    });

</script>
</body>

</html>
